
class TreeNode {
    constructor(val, left, right) {
        this.val = val
        this.left = left
        this.right = right
    }
}

function preOrder(root) {
    // 最小子问题
    if (!root) return
    // 遍历打印根节点
    console.log(root.val)
    // 遍历左子树
    preOrder(root.left)
    // 遍历右子树
    preOrder(root.right)
}

function inOrder(root) {
    // 最小子问题
    if (!root) return
    // 遍历左子树
    inOrder(root.left)
    // 遍历打印根节点
    console.log(root.val)
    // 遍历右子树
    inOrder(root.right)
}

function postOrder(root) {
    // 最小子问题
    if (!root) return
    // 遍历左子树
    postOrder(root.left)
    // 遍历右子树
    postOrder(root.right)
    // 遍历打印根节点
    console.log(root.val)
}

const node5 = new TreeNode(7, null, null)
const node4 = new TreeNode(11, null, null)
const node3 = new TreeNode(23, null, null)
const node2 = new TreeNode(9, null, node5)
const node1 = new TreeNode(8, node3, node4)
const root = new TreeNode(10, node1, node2)

preOrder(root)